package com.wk.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wk.annotation.LogAnnotation;
import com.wk.dao.CmfzGuruDao;
import com.wk.entity.CmfzAdmin;
import com.wk.entity.CmfzGuru;
import com.wk.service.CmfzGuruService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CmfzGuruServiceImpl implements CmfzGuruService {

    @Autowired
    private CmfzGuruDao cmfzGuruDao;
    @LogAnnotation(content = "查询所有上师")
    @Override
    public Map findAll(Integer page, Integer limit) {

        Page<CmfzGuru> cmfzGuruPage = new Page<CmfzGuru>(page, limit);

        Page<CmfzGuru> page2 = cmfzGuruDao.selectPage(cmfzGuruPage, null);

        long total = page2.getTotal();

        List<CmfzGuru> records = page2.getRecords();

        Map map = new HashMap();

        map.put("data", records);
        map.put("msg", "");
        map.put("code", 0);
        map.put("count", total);



        return map;
    }

    @LogAnnotation(content = "查询指定上师")
    @Override
    public Map findGuru() {
        Map map = new HashMap();
        List<CmfzGuru> cmfzGurus = cmfzGuruDao.selectList(null);
        log.info("查询到的上师"+cmfzGurus);
        System.out.println("list" + cmfzGurus);
        map.put("data", cmfzGurus);
        return null;
    }

    @Override
    public Map uploadExcel() {
        return null;
    }


    @Override
    public Map mutilAdd(List<CmfzGuru> gurus) {

        Map map = new HashMap();
        map.put("data", "添加失败");
        try {
            cmfzGuruDao.multiAdd(gurus);
            log.info("添加上师成功");
            map.put("data", "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加上师失败");
            throw e;
        }
        return map;
    }

    @Override
    public List<CmfzGuru> selectList() {
        return cmfzGuruDao.selectList(null);
    }
}
